<!-- 随机出题 -->
<template>
  <div class="randomlyGenerateQuestions-page">
    <div class="card-box" v-if="list.length > 0">
      <div class="card-box-line">
        <div class="card-box-g">
          <div class="card-box-item" v-for="item in list">
            <div class="card-box-item-img">
              <img src="@/assets/img/img2.png" alt="">
            </div>
            <div class="card-box-item-content">
              <div class="card-box-item-title">{{ item.title }}</div>
              <div class="card-box-item-n">题目数量：{{ item.item_number }}道</div>
              <div class="card-box-item-n">满分：{{ item.total_score }}分</div>
              <div class="card-box-item-n">及格分：{{ item.passing_mark }}分</div>
              <div class="card-box-item-n">考试时长：{{ item.exam_time }}分钟</div>
              <div class="card-box-item-btns">
                <div class="card-btn" @click="handelClick(item)">开始考试</div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <el-empty v-else description="暂无数据"></el-empty>
  </div>
</template>

<script>
import {getHomeOldRecord, getSimulatedExam, getSubmitTheTestPaper, login} from "@/api";

export default {
  name: "randomlyGenerateQuestions",
  data(){
    return {
      list: [],
      userInfo: {}
    }
  },
  mounted() {
    this.userInfo = JSON.parse(localStorage.getItem('userInfo'))
    this.getSimulatedExam()
  },
  methods: {
    //
    getSimulatedExam() {
      let params = {
        category_id: 9,
        career_id: this.userInfo.career_id,
        level_id: this.userInfo.level_id,
        direction_id : this.userInfo.direction_id,
      }
      getSimulatedExam(params).then(res => {
        this.list = res.data.list.data || []
      })
    },
    // 跳转考试页面
    handelClick(item) {
      getHomeOldRecord({paper_id: item.paper_id}).then(res => {
        if (res.code == 1) {
          if (res.data) {
            this.submitClick(res.data.record_id, item)
          } else {
            this.$router.push({
              path: '/examManage',
              query: {
                paper_id: item.paper_id
              }
            })
          }
        }
      })
    },
    // 确认交卷
    submitClick(recordId, item) {
      let params = {record_id: recordId}
      getSubmitTheTestPaper(params).then(res => {
        if (res.code == 1) {
          this.$router.push({
            path: '/examManage',
            query: {
              paper_id: item.paper_id
            }
          })
        }
      })
    },

    // 时间计算
    getDuration(e) {
      let seconds = e
      let hours = Math.floor(seconds / 3600);
      seconds %= 3600;
      let minutes = Math.floor(seconds / 60);
      seconds %= 60;
      let a = hours == 0 ? '00' : hours < 10 ? '0' + hours : hours
      let b = minutes == 0 ? '00' : minutes < 10 ? '0' + minutes : minutes
      let c = seconds.toFixed(0) == 0 ? '00' : seconds.toFixed(0) < 10 ? '0' + seconds.toFixed(0) : seconds.toFixed(0)
      return `${a}:${b}:${c}`
    },

  }
}
</script>

<style lang="scss" scoped>
.randomlyGenerateQuestions-page {
  width: 100%;
  height: 100%;
}
</style>
